<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bpmn文件列表</title>
    <script type="application/javascript" src="js/jquery-1.11.1.min.js"></script>
    <script>
        $(function () {

            // 加载 bpmn 列表
            $.ajax({
                type: "POST",
                url: "http://127.0.0.1:8087/flow/bpmn/list",
                dataType:"json",
                data: {},
                async: false,
                success: function (data) {
                    var list = data.model;
                    var appendHtml = "";
                    for(var i=0;i<list.length;i++){
                        var m  = list[i];
                        appendHtml = appendHtml + "<tr><td>"+m.name+"</td>" +
                            "<td>"+m.type+"</td>"+
                            //"<td>"+m.fullName+"</td>"+
                            "<td>" +
                            "<button onclick=\"deploy('"+m.fullName+"')\">部署</button>&nbsp;&nbsp;&nbsp;" +
                            "<button onclick=\"deletes('"+m.fullName+"')\">删除</button>" +
                            "</td>" +
                            "</tr>";
                    }
                    $("#tablelist").append(appendHtml);
                },
                error: function(data) {
                    console.log("出错："+data);
                }
            });



            // 加载 已经部署的 bpmn 流程
            inintDeployedFlow();

        });

        // 加载 已经部署的 bpmn 流程
        function inintDeployedFlow() {
            $.ajax({
                type: "POST",
                url: "http://127.0.0.1:8087/flow/deployed/list",
                dataType:"json",
                data: {},
                async: false,
                success: function (data) {
                    var list = data.model;
                    var appendHtml = "";
                    for(var i=0;i<list.length;i++){
                        var m  = list[i];
                        appendHtml = appendHtml + "<tr><td>"+m.id+"</td>" +
                            "<td>"+m.processDefinitionName+"</td>"+
                            "<td>"+m.processDefinitionKey+"</td>"+
                            "<td>"+m.processDefinitionVersion+"</td>"+
                            "<td>"+m.deploymentId+"</td>"+
                            "<td>"+m.businessKey+"</td>"+
                            "<td>"+m.isSuspended+"</td>"+
                            "<td>" +
                            "<button onclick=\"deploy('"+m.fullName+"')\">部署</button>&nbsp;&nbsp;&nbsp;" +
                            "<button onclick=\"deletes('"+m.fullName+"')\">取消部署流程</button>" +
                            "</td>" +
                            "</tr>";
                    }
                    $("#tablelist2").append(appendHtml);
                },
                error: function(data) {
                    console.log("出错："+data);
                }
            });


        }


    </script>
</head>
<body>


<h1>可以部署的流程bpmn</h1>
<div style="padding: 30px;">

    <table id="tablelist" border="1">
        <tr align="center">
            <td>名称</td>
            <td>文件类型</td>
            <td>操作</td>
        </tr>
    </table>

<hr/>








    <h1>已经部署的流程bpmn</h1>
    <table id="tablelist2" border="1">


        <tr align="center">
            <td>id</td>
            <td>ProcessDefinitionName</td>
            <td>ProcessDefinitionKey</td>
            <td>ProcessDefinitionVersion</td>
            <td>DeploymentId</td>
            <td>BusinessKey</td>
            <td>isSuspended</td>
            <td>操作</td>
        </tr>
    </table>

</div>


</body>


<script>


    /**部署流程 */
    function deploy(id) {
        if(confirm("确定部署："+id)){
            $.ajax({
                type: "POST",
                url: "http://127.0.0.1:8087/flow/deploy",
                dataType:"json",
                data: {"processName":id},
                async: false,
                success: function (data) {
                    alert("成功");
                },
                error: function(data) {
                    alert("失败");
                    console.log("出错："+data);
                }
            });
        }


    }



    function deletes(id) {
        if(confirm("确定删除吗?")){
            $.ajax({
                type: "POST",
                url: "http://127.0.0.1:8087/scheduled/delete/",
                dataType:"json",
                data: {"id":id},
                async: false,
                success: function (data) {
                    alert("已删除");
                    location.reload();
                },
                error: function(data) {
                    console.log("出错："+data);
                }
            });
        }
    }





</script>


</html>
